clear all
cap log close
set more off

* set master directory here ----------------
global proj = ""
* ------------------------------------------

* if necessary, set R library here ---------
global rlib = ""
* ------------------------------------------

* set location of code directory -----------
global code = "${proj}/code"
* ------------------------------------------

* if necessary, install packages -----------
*do "${code}/utility/setup_stata.do"
*rscript using "${code}/utility/setup_r.R", args("${proj}" "${rlib}")
* ------------------------------------------

* create main directories ------------------
mkdir "${proj}/logs" 
mkdir "${proj}/estimates"
mkdir "${proj}/output"
mkdir "${proj}/_temp" 
* ------------------------------------------

* create subdirectories --------------------
mkdir "${proj}/data/out" 
mkdir "${proj}/output/main"
mkdir "${proj}/output/apx_iv"
mkdir "${proj}/output/apx_deter"
mkdir "${proj}/output/apx_extrap"
* ------------------------------------------

* run main programs ------------------------
do "${code}/01-data_construct.do"
do "${code}/02-iv_checks.do"
do "${code}/03-iv_analysis.do"
do "${code}/04-extrap_base.do"
do "${code}/05-extrap_hetero.do"
* ------------------------------------------

* delete temporary directory ---------------
local files: dir "${temp}" files "*"
foreach file in `files' {
	rm "${temp}/`file'"
}
rmdir "${temp}"
* ------------------------------------------





